<template>
	<view>
		<block v-for="(item,index) in list" :key="index">
			<view class="bg-white u-m-28 u-b-28 u-p-l-30 u-p-r-30 u-p-b-12 u-p-t-8 list">
				<view class="u-flex u-border-bottom u-m-b-20 u-p-b-20 u-m-t-20 ">
					<u-image width="80" height="80" src="@/static/images/LOGO.png"></u-image>
					<view class="u-flex-1 u-p-l-24 u-p-r-24">
						<view class="u-font-lg fw-large">{{item.userName}}</view>
						<view class="u-font-sm color_defaul">{{item.completeRemark}}</view>
					</view>
					<view style="display: flex;flex-direction: column;align-items: flex-end;">
						<block v-if="item.cashState==1">
							<text class="success">提现中</text>
						</block>
						<block v-else-if="item.cashState==5">
							<text class="success">已提现</text>
						</block>
						<block v-else-if="item.cashState==10 ">
							<text class="success">未到账</text>
						</block>
						<block v-else-if="item.cashState==15 ">
							<text class="success">提现失败</text>
						</block>
						<block v-else-if="item.cashState==20 ">
							<text class="success">提现成功</text>
						</block>
						<text class="u-font-24 success">+{{item.amount}}</text>
					</view>
				</view>
				<view class="u-font-xs u-border-bottom u-p-b-15" style="line-height: 1.8;">
					<view class="u-flex u-row-between ">
						<text class=" color_defaul">提现时间:{{item.paymentDate}}</text>
					</view>
					<view class="u-flex u-row-between ">
						<text class=" color_defaul">编号:{{item.cashNo}}</text>
					</view>
					<view class="u-flex u-row-between ">
						<text class=" color_defaul">内容:{{item.insideRemark}}</text>
					</view>
				</view>
				<view class="u-flex u-row-right u-m-t-22">
					<block v-if="item.cashState ==5">
						<u-button @click="itemSet('no',item)" class="u-m-l-22" type="error" size="mini">未到账</u-button>
					</block>

					<block v-if="item.cashState ==5">
						<u-button @click="itemSet('yes',item)" class="u-m-l-22" type="warning" size="mini"
							:custom-style="{backgroundColor:'#ffc300'}">已到账</u-button>
					</block>

				</view>
			</view>
		</block>
	</view>
</template>

<script lang="ts" setup>
	import { onLoad, onReachBottom } from '@dcloudio/uni-app'
	import userApi from '@/api/user'
	import { reactive, ref } from "vue";

	const params = reactive({
		pageNo: 1,
		pageSize: 10,
	})
	const list = ref([])
	/**
	 * 提现列表
	 */
	function getList(type, callback) {
		if (!type) {
			list.value = []
			params.pageNo = 1
		}
		userApi.getWiteCard(params).then(res => {
			list.value = res.data.list
			if (list.value.length < res.data.total) {
				params.pageNo + 1
			}
			if (callback) {
				uni.stopPullDownRefresh()
			}
		})
	}

	/**
	 * 设置状态
	 */
	function itemSet(type, item) {
		uni.showModal({
			title: '提示',
			content: '是否确认操作',
			success: (res) => {
				if (res.confirm) {
					let obj = {
						id: item.cashRecordId,
					}
					switch (type) {
						case 'no':
							obj.state = 10
							break;

						case 'yes':
							obj.state = 20
							break;
					}
					userApi.setcashState(obj).then(result => {
						switch (type) {
							case 'no':
								item.cashState = 10
								break;

							case 'yes':
								item.cashState = 20
								break;
						}
					})




				}

			}
		})
		// userApi.setcashState()
	}

	onLoad(() => {
		getList()
	})

	onReachBottom(() => {
		getList('add')
	})
</script>

<style>
	page {
		background-color: #f6f3f7;
	}
</style>
<style lang="scss">
	.success {
		color: #51c19d;
	}

	.color_defaul {
		color: #999999;
	}

	.list {
		box-shadow: 0upx 4upx 8upx rgba(100, 100, 100, .1);
	}
</style>
